{include file = $smarty.const.APPLICATION_PATH|cat:"/application/views/header.html"}
{include file = $smarty.const.APPLICATION_PATH|cat:"/application/views/common/headertitle.html"}

<div style="height:48px;"></div>
<section class="wp_fixed">
    <p class="self-stock-title bff"><span class="orange">配送方式</span></p>
    <p class="tgb_radio delivery ">
        <label class="pr10p j_psn"><input name="zt" type="radio" class="btn_radio" {if $user_action.area_id eq 'T'}checked="checked"{/if} value="T"> 自提</label>
        <label class="pr10p j_ps"><input name="zt" class="btn_radio" {if $user_action.area_id eq 'S'}checked="checked"{/if}  type="radio" value="S"> 配送</label>
        <input type="text" name="delivery_addr" style="border: 1px solid #ddd; line-height: 26px; padding: 1px 5px;" placeholder="请输入您的配送地址！" value="" class="j_pssh delivery_addr {if $user_action.area_id eq 'T'}dn{/if} ml10 sp_int">
    </p>

    <div class="tgb_wrmg">
        <p class="self-stock-title bff"><span class="orange">联系信息</span></p>
        <ul class="to-c" style="background:#fff;">

            {if $contacts eq ''}
            <li class="conpany" value="1"><span class="">公司名称：</span><input type="text" value="" name="business_name" class="to-c-fp"></li>
            <li><span class="">联 系 人 ：</span><input type="text" name="contacts" class="to-c-fp" placeholder="请填写联系人"/></li>
            <li><span class="">手机号码：</span><input type="text" name="mobile" class="to-c-fp" placeholder="请填写手机号码"/></li>
            {else}
            <li class="conpany" value="2"><span class="sp_ts">选择公司：</span>
                <select name="sup_id" class="to-c-fp" id="select">
                    {foreach from=$conpanylist key=key item=item}
                    <option value="{$item.id}" {if $item.is_default == 'Y'}selected{/if}>{$item.business_name}</option>
                    {/foreach}
                </select>
            </li>
            <li><span class="">联 系 人 ：</span><span class="text_contacts">{$contacts.contacts}</span></li>
            <li><span class="">手机号码：</span><span class="text_mobile">{$contacts.mobile}</span></li>
            {/if}
        </ul>
    </div>

    <div class="self-stock mt10p">

        {foreach from=$order_info.order_sku key=key item=item}
        <p class="self-stock-title bff"><span class="orange">商品清单</span></p>
        <p class="self-stock-title">{$item.cate_name} {$item.product_name} {$item.brand_name} </p>
        <p class="fs14p orange pl10p pt10p"><span class="fs14p">{$item.currency_mark} </span>{$item.price}<span class="fs14p">元/吨</span></p>
        <p class="sst-te"><span class="sst-te2">厂商：{$item.brand_name}</span><span class="sst-te1">产品类型：{$item.service_name}</span></p>
        <p class="sst-te"><span class="sst-te2">交货时间：{$item.delivery_time}</span><span class="sst-te1">交货地点：{$item.delivery_area}</span></p>
        {if $item.settlement neq ''}<p class="sst-te"><span class="sst-te1">结算方式：{$item.settlement}</span></p>{/if}
        <ul class="to-c" style="background:#fff;">
            <li><span>数量：</span><input name="product_num" num="{$item.real_num}" price="{$item.price}" product_id="{$item.product_id}" type="text" class="to-c-fp product_num" style="min-width:80px;width:80px;" value="5" placeholder="请填写数量"/>/吨</li>
        </ul>
        {/foreach}
        <p class="sale_zr">应付总额：<span class="orange fwb ">{$product.currency_mark}</span> <span class="orange fwb total_price">{$product.price * 5}</span></p>
        <div class="sub-order "><a href="#">提交订单</a></div>

    </div>



</section>

{literal}
<script typte="text/javascript">
    $(function(){
        $('.j_ps').click(function(){
            $('.j_pssh').show();
        });
        $('.j_psn').click(function(){
            $('.j_pssh').hide();
        });


        //更新配送方式
        $(".btn_radio").click(function(){
            var dm = $("input[name='zt']:checked").val();
            var dr = $("input[name='delivery_addr']").val();
            $.ajax({
                url:'/shopcart/delivery',
                data:{dm:dm,dr:dr},
                type:'POST',
                success:function(data){
                    return true;
                },
                dataType:'text'
            });
        });

        $(".delivery_addr").blur(function(){
            var dr = $("input[name='delivery_addr']").val();

            $.ajax({
                url:'/shopcart/delivery_addr',
                data:{dr:dr},
                type:'POST',
                success:function(data){
                    return;
                },
                dataType:'text'
            });
        });

        //选择公司
        $("#select").change(function(){
            var select_id=$("#select option:selected").val();

            $.ajax({
                url:'/shopcart/user_invoice',
                data:{select_id:select_id},
                type:'POST',
                success:function(data){
                    data = eval("("+data+")");
                    if(data.code == 8 ){
                        var d = data.data;
                        $('input[name="business_name"]').val(d.business_name);
                        $('input[name="business_remarks"]').val(d.business_remarks);
                        $('input[name="business_phone"]').val(d.business_phone);
                        $('.text_contacts').text(d.contacts);
                        $('.text_mobile').text(d.mobile);
                    }
                },
                dataType:'text'
            });
        });


        $('input.product_num').change(function(){
            var pn = $(this);
            var tp = $(".total_price");
            var product_num = parseFloat(pn.val());
            var real_num = parseFloat(pn.attr('num'));
            var price = pn.attr('price');

            if(product_num < 1){
                alert("数量不可少于1吨！");
                pn.val("1");
                product_num = pn.val();
                tp.text(product_num*price);
            }

            if(product_num > real_num){
                alert("不可超过可售数量！");
                pn.val(real_num);
                product_num = pn.val();
                tp.text(product_num*price);
                //开始更新数量
                update_product_num(product_num)
            }else{
                product_num = pn.val();
                tp.text(product_num*price);
                update_product_num(product_num)
            }
        });

        function update_product_num(product_num){
            $.ajax({
                url:'/shopcart/updatenum',
                data:{product_num:product_num},
                type:'POST',
                success:function(data){
                    return;
                },
                dataType:'text'
            });
        }

        $('.sub-order').click(function(){ //去结算，提交跟新购物车
            var cp = $(".conpany").attr("value");

            if(cp === 1){
                var bn = $("input[name=business_name]").val();
                var ct = $("input[name=contacts]").val();
                var mb = $("input[name=mobile]").val();

                if(bn == '' && bn.length>8){
                    alert("请维护正确公司名称！");
                    return false;
                }

                if(ct == ''){
                    alert("请维护正确联系人！");
                    return false;
                }

                if(mb =='' && !mb.match(/^(?:13\d|15\d|18\d)\d{5}(\d{3}|\*{3})$/)){
                    alert("请维护正确手机号码！");
                    return false;
                }

                $.ajax({
                    url:'/shopcart/addinvoice',
                    data:{business_name:bn,contacts:ct,mobile:mb},
                    type:'POST',
                    async:false,
                    success:function(data){
                        data = eval("("+data+")");
                        if(data.code == 8 ){
                            var url = "/shopcart/createorder";
                            window.location = url;
                            return true;
                        }else{
                            alert(data.msg);
                            return false;
                        }
                    },
                    dataType:'text'
                });

            }else{
                var url = "/shopcart/createorder";
                window.location = url;
            }


        });
    });
</script>
{/literal}

